home *** CD-ROM | disk | FTP | other *** search
/ 300 Plus Way Cool Games for Windows / 300 Plus Way Cool Games for Windows.iso / games / bang / bang.c next >
Encoding:
Text File  |  1992-06-09  |  41.9 KB  |  1,305 lines

  1.  /* ----- BANG.C -------------------------------------------------------------
  2.   *
  3.   *   DESCRIPTION:
  4.   *
  5.   *            Sample Program for Destroying WinDoom errors
  6.   *            (that means everything)
  7.   *
  8.   *   REMARKS:
  9.   *            Needed files are only the resource file PENG.RES.
  10.   *            Compilation without explicit .DEF file.
  11.   *
  12.   *   CHANGES:
  13.   *
  14.   *        V0.1    09-11-91    Heiner Eichmann
  15.   *                             & Michael Schuschk
  16.   *                Desperate start of programming.
  17.   *
  18.   *        V0.2    10-11-91    Heiner Eichmann
  19.   *                             & Jⁿrgen Christ
  20.   *                Cleaned up program code and brought to first time
  21.   *                functioning (a real strong performance for a
  22.   *                pascal programmer). Shooting within and without the
  23.   *                window is possible.
  24.   *
  25.   *        V0.25   12-11-91    Michael Schuschk
  26.   *                Fixed bug with crippled shots appearing when window
  27.   *                is iconized and resized again. Screen is saved at
  28.   *                program start and will be restored before ending the
  29.   *                program.
  30.   *
  31.   *        V0.3    22-11-91    Heiner Eichmann
  32.   *                There's only an ABOUT dialog box and the sound
  33.   *                missing. All other things are the way we wanted
  34.   *                them.
  35.   *
  36.   *        V0.35   24-11-91    Michael Schuschk
  37.   *                ABOUT box with informations about this ultimate
  38.   *                program added. Window size at first start is
  39.   *                now depending on the width of the text lines
  40.   *                appearing within the window.
  41.   *
  42.   *        V0.4    25-11-91    Heiner Eichmann
  43.   *                Only slight corrections. Translation of text and
  44.   *                comments into english language. Now only the sound
  45.   *                is missing.
  46.   *
  47.   *        V0.5    26-11-91    Michael Schuschk
  48.   *                Slight corrections on the ABOUT box and shooting
  49.   *                hole design. And new in this version: the first
  50.   *                appearance of sound! But until now it sounds only
  51.   *                like a gun with sound absorber. This "pop" will
  52.   *                possibly be caused by the StartSound() and
  53.   *                StopSound() functions.
  54.   *
  55.   *              - Program goes into Beta-Test!
  56.   *
  57.   *        V0.6    27-11-91    Jⁿrgen Christ & Heiner Eichmann
  58.   *                New cursor created. The word WinDoom was discovered
  59.   *                (Many thanks to Holger Eichmann). A small problem
  60.   *                with the distribution of the painted holes around
  61.   *                the cross-hair if fixed. The About About... window
  62.   *                was created. Problems with the aboutbitmap.
  63.   *
  64.   *        V1.0    03-12-91    Heiner Eichmann
  65.   *                Problems with the aboutabout-resource ignored. Light
  66.   *                changes of the sound-commands. CloseSound() bug fixed.
  67.   *                Version number changed to 1.0!!!!! Install and
  68.   *                document created. Program is now ready to mail.
  69.   *
  70.   *        V1.1    18-04-92    Jⁿrgen Christ
  71.   *                Sound is now produced through Mulimedia-Controller-
  72.   *                Interface (MCI). Great digitized sound via
  73.   *                Soundblaster or similar WAVEFORM-devices.
  74.   *
  75.   *        V1.11   19-04-92    Heiner Eichmann and Jⁿrgen Christ
  76.   *                First appearence of the Hasta-La-Vista-Sound! We should
  77.   *                not mention, what movie is our favorite, should we!?
  78.   *
  79.   *        V1.2    20-04-92    Jⁿrgen Christ
  80.   *                All soundparameters can be installed via config-dialog.
  81.   *                BANG uses for the first time WIN.INI without adding ONLY
  82.   *                rubbish. :-)
  83.   *
  84.   *        V1.21   20-04-92    Heiner Eichmann
  85.   *                Added enhanced grenade-functions, fixed problems with
  86.   *                Hasta-la-Vista-Sound at the end of firing.
  87.   *
  88.   *              - Program goes into Beta-Test!
  89.   *
  90.   *        V1.3    21-04-92    Jⁿrgen Christ
  91.   *                Added statistics-box - counts your hits on WINDOOM!
  92.   *
  93.   *        V1.35   21-04-92    Heiner Eichmann
  94.   *                He IS the bug-hunter!!! :-) Uncounted minor errors fixed in
  95.   *                several cases.
  96.   *
  97.   *        V1.4    26-04-92    Heiner Eichmann
  98.   *                Time event structure changed and autoinit procedure added
  99.   *
  100.   *        V1.5    02-05-92    Jⁿrgen Christ
  101.   *                BANG looks for a MCI-Driver which kann play waves! Otherwise BANG
  102.   *                playes some PC-QuΣker-Sounds!
  103.   *
  104.   *        V1.6    03-05-92    Jⁿrgen Christ and Heiner Eichmann
  105.   *                Help-Menue added and Help-text created.
  106.   *                This part brought much fun! :-)
  107.   *
  108.   *        V1.7    10-05-92     Heiner Eichmann
  109.   *                Program structure changed. Now not more than 3 DC are
  110.   *                open. ... This was NOT the cause of the "Mystic crashes".
  111.   *
  112.   *        V1.75   16-05-92     Heiner Eichmann
  113.   *                We forgot the EndPaint function under WM_PAINT.
  114.   *                ARGHNF - This was the cause of the mystic crashes !!
  115.   *
  116.   *        V1.76   17-05-92     Heiner Eichmann
  117.   *                Small MCI-Bug removed: MCI-Driver is now available after
  118.   *                iconizing and resizing BANG
  119.   *
  120.   *              - Program goes into Beta-Test!
  121.   *
  122.   *        V1.80   20-05-92     Heiner Eichmann
  123.   *                I give up ! WinDoom is too clever. Each procedure to prevent
  124.   *                sound errors is bypassed by Windoom. Therefore the Sound Mode
  125.   *                entry in Config has to be created.
  126.   *
  127.   *        V1.81   22-05-92     Heiner Eichmann
  128.   *                The Combo-box is working and the auto-detect routine is
  129.   *                improved
  130.   *
  131.   *        V1.90   31-05-92     Heiner Eichmann & Jⁿrgen Christ
  132.   *                It's finally working!
  133.   *                BANG now stops all playing WAVEs.
  134.   *                Thanks to sndPlaySound!!!
  135.   *
  136.   *        V1.91   31-05-92     Heiner Eichmann
  137.   *                Two minor Bugs fixed
  138.   *
  139.   *             - Program goes into final Beta-Test !
  140.   *
  141.   *        V1.92   06-06-92     Jⁿrgen Christ
  142.   *                Minor Bug-Fix in Windows-Help-Procedure call.
  143.   *
  144.   *        V1.95   07-06-92     Jⁿrgen Christ
  145.   *                Implementation of a REAL RestoreScreen-Funktion using
  146.   *                Windows 3.1-features! It has lasted long, really long!!
  147.   *
  148.   *        V2.0    09-06-92     Heiner Eichmann, Jⁿrgen Christ
  149.   *                Final changes (all BETA's removed, logo changed).
  150.   *                BANG 2.0 is released to the public !!!!
  151.   *
  152.   *     The last problem: is there any known rule in the way we are giving the
  153.   *                       version numbers ???
  154.   *
  155.   *
  156.   *   INCLUDES:
  157.   */
  158.  #include <windows.h>
  159.  #include <string.h>
  160.  #include <stdlib.h>
  161.  #include <stdio.h>
  162.  /*
  163.   *   DEFINES:
  164.   */
  165.  
  166.  /* Defines and types from MMSYSTEM.H of the Multimedia-SDK from Mickersoft
  167.     in the damned fucking Mickersoft-format!!!
  168.  */
  169.  
  170.  #define MCI_STRING_OFFSET      512
  171.  #define MCI_VD_OFFSET          1024
  172.  #define MCI_CD_OFFSET          1088
  173.  #define MCI_WAVE_OFFSET        1152
  174.  #define MCI_SEQ_OFFSET         1216
  175.  #define MCI_ALL_DEVICE_ID    0xFFFF
  176.  
  177.  #define MCI_DEVTYPE_WAVEFORM_AUDIO      (MCI_STRING_OFFSET + 10)
  178.  
  179.  // MCI command message identifiers
  180.  #define MCI_OPEN                        0x0803
  181.  #define MCI_CLOSE                       0x0804
  182.  #define MCI_ESCAPE                      0x0805
  183.  #define MCI_PLAY                        0x0806
  184.  #define MCI_SEEK                        0x0807
  185.  #define MCI_STOP                        0x0808
  186.  #define MCI_PAUSE                       0x0809
  187.  #define MCI_INFO                        0x080A
  188.  #define MCI_GETDEVCAPS                  0x080B
  189.  #define MCI_SPIN                        0x080C
  190.  #define MCI_SET                         0x080D
  191.  #define MCI_STEP                        0x080E
  192.  #define MCI_RECORD                      0x080F
  193.  #define MCI_SYSINFO                     0x0810
  194.  #define MCI_BREAK                       0x0811
  195.  #define MCI_SOUND                       0x0812
  196.  #define MCI_SAVE                        0x0813
  197.  #define MCI_STATUS                      0x0814
  198.  #define MCI_CUE                         0x0830
  199.  #define MCI_REALIZE                     0x0840
  200.  #define MCI_WINDOW                      0x0841
  201.  #define MCI_PUT                         0x0842
  202.  #define MCI_WHERE                       0x0843
  203.  #define MCI_FREEZE                      0x0844
  204.  #define MCI_UNFREEZE                    0x0845
  205.  #define MCI_LOAD                        0x0850
  206.  #define MCI_CUT                         0x0851
  207.  #define MCI_COPY                        0x0852
  208.  #define MCI_PASTE                       0x0853
  209.  #define MCI_UPDATE                      0x0854
  210.  #define MCI_RESUME                      0x0855
  211.  #define MCI_DELETE                      0x0856
  212.  
  213.  // all custom MCI command messages must be >= than this value
  214.  #define MCI_USER_MESSAGES               (0x400 + DRV_MCI_FIRST)
  215.  
  216.  // return values for 'status mode' command
  217.  #define MCI_MODE_NOT_READY              (MCI_STRING_OFFSET + 12)
  218.  #define MCI_MODE_STOP                   (MCI_STRING_OFFSET + 13)
  219.  #define MCI_MODE_PLAY                   (MCI_STRING_OFFSET + 14)
  220.  #define MCI_MODE_RECORD                 (MCI_STRING_OFFSET + 15)
  221.  #define MCI_MODE_SEEK                   (MCI_STRING_OFFSET + 16)
  222.  #define MCI_MODE_PAUSE                  (MCI_STRING_OFFSET + 17)
  223.  #define MCI_MODE_OPEN                   (MCI_STRING_OFFSET + 18)
  224.  
  225.  // flags for dwFlags parameter of MCI_SYSINFO command message
  226.  #define MCI_SYSINFO_QUANTITY            0x00000100L
  227.  #define MCI_SYSINFO_OPEN                0x00000200L
  228.  #define MCI_SYSINFO_NAME                0x00000400L
  229.  #define MCI_SYSINFO_INSTALLNAME         0x00000800L
  230.  
  231.  // Sound support
  232.  // flag values for wFlags parameter
  233.  #define SND_SYNC            0x0000  // play synchronously (default)
  234.  #define SND_ASYNC           0x0001  // play asynchronously
  235.  #define SND_NODEFAULT       0x0002  // don't use default sound
  236.  #define SND_MEMORY          0x0004  // lpszSoundName points to a memory file
  237.  #define SND_LOOP            0x0008  // loop the sound until next sndPlaySound
  238.  #define SND_NOSTOP          0x0010  // don't stop any currently playing sound
  239.  
  240.  // parameter block for MCI_SYSINFO command message
  241.  typedef struct {
  242.      DWORD   dwCallback;
  243.      LPSTR   lpstrReturn;
  244.      DWORD   dwRetSize;
  245.      DWORD   dwNumber;
  246.      WORD    wDeviceType;
  247.      WORD    wReserved0;
  248.  } MCI_SYSINFO_PARMS;
  249.  typedef MCI_SYSINFO_PARMS FAR * LPMCI_SYSINFO_PARMS;
  250.  
  251.  /* Own defines */
  252.  
  253.  #define STARTPOSX     CW_USEDEFAULT
  254.  #define STARTPOSY     CW_USEDEFAULT
  255.  #define RANGEXDIV     20
  256.  #define RANGEYDIV     20
  257.  #define ENDDELAY    100    /* Delay between two accesses to the MCI driver */
  258.  #define GRENADEDELAY    1500    /* Delay between trigger and Explosion */
  259.  #define EXPLOSIONDELAY    3    /* Delay for speaker explosion */
  260.  #define EXPLOSIONNUMBER 10    /* Number of soundchanges during explosion */
  261.  #define HALF_SIZE    8       /* Size of icon LOCH div 2 */
  262.  #define IDM_SYSABOUT    4242
  263.  #define ID_OK        101
  264.  #define IDM_ABOUTABOUT 6942
  265.  
  266.  /* timer events: */
  267.  
  268.  #define PENG        1    /* time between two shots */
  269.  #define GRENADE        2    /* time between right trigger and explosion */
  270.  #define ENDGRENADE    3    /* time between explosion and end of sound */
  271.  #define HASTALAVISTA    4    /* time between right double click and end of sound */
  272.  
  273.  #define IDM_CONFIG      4711
  274.  #define ID_SAVE         108
  275.  #define ID_FORGET       109
  276.  #define ID_SPEED        104
  277.  #define ID_SLIDER       105
  278.  #define ID_GRENADEDELAY 106
  279.  #define ID_MG           111
  280.  #define ID_GT           112
  281.  #define ID_HLVB         113
  282.  #define ID_PATHTOSOUND  114
  283.  #define ID_SOUNDMODE     115
  284.  
  285.  #define IDM_STATS    815
  286.  #define ID_RESET    102
  287.  #define ID_SHOTS    103
  288.  #define ID_GRENADES    104
  289.  
  290.  #define IDM_HELP    1811
  291.  /*
  292.   *   EXTERNAL:
  293.   */
  294.  /*
  295.   *   TYPES:
  296.   */
  297.  /*
  298.   *   VARIABLES:
  299.   */
  300.  HCURSOR hcursor, gaehn_cursor;
  301.  HANDLE  scheiss_c;
  302.  HDC    screen_hdc, hdcmem;
  303.  HBITMAP    screen_bitm, hole_bitm, grenade_bitm;
  304.  POINT    ptSize_hole, ptSize_grenade, ptOrg;
  305.  BITMAP    bm;
  306.  short    cxSize, cySize;
  307.  int    rangex, rangey;
  308.  int     GrenadeDelay=GRENADEDELAY;
  309.  int    oldgrenade;
  310.  int    grenade_x, grenade_y;    /* position of grenade hit */
  311.  int     grenade_ready;        /* ready to shoot */
  312.  char    OldInfoStr[42];         /* WinDoom-into-the-trashcan information */
  313.  int    treffer_flag,
  314.     hdc_in_use = FALSE;
  315.  int    iMaxZeile;        /* Maximum width of text in pixel */
  316.  short    cxChar, cxCaps, cyCaps;    /* Dimensions of one char of actual
  317.                    system font */
  318.  HWND    hSlider;                /* Handle to a slider */
  319.  int     FirePlace;              /* Update - variable */
  320.  
  321.  int     ShotsOnWinDoom;         /* Hits on the Desktop */
  322.  int     ThrownGrenades;
  323.  int     WAVerror;        /* True, if an error occures */
  324.  int     soundinstalled;        /* speakersound installed */
  325.  int     MCIDriverInstalled;    /* what could this mean ? */
  326.  int     first_play_command;
  327.  int      MCImode;        /* Mci modes: */
  328.  #define AUTO         0
  329.  #define SPEAKER    1
  330.  #define MCIDEVICE    2
  331.  char     SoundModeStrings[3][10]={
  332.         "AUTO","SPEAKER","MCIDEVICE"};
  333.  
  334.  int    speaker_explosion;    /* grenade ie exploding (for speaker sound only) */
  335.  int    explosion_counter;    /* counter for speaker-explosion sound */
  336.  
  337.  
  338.  #define LINENUMS     9
  339.  char    acText[LINENUMS][100] = {
  340.     "Death to Mickeysoft Version 2.0",
  341.     "",
  342.     "The program, everyone was waiting for",
  343.     "",
  344.     "Left mousebutton: Fire MG!",
  345.     "Right mousebutton: Fire Grenade!",
  346.     "Right doubleclick: Back to work.",
  347.     "",
  348.     "Written by REMBRANDT, POWER MIKE and JOSH."};
  349.  
  350.     /* Variables for WIN.INI access */
  351.     int HowMuch;
  352.     char WhereBang[51];
  353.     char MachineGun[13];
  354.     char GrenadeThrower[13];
  355.     char HastaLaVista[13];
  356.     char strGrenadeDelay[10];
  357.     char strFireSpeed[10];
  358.     char strSoundMode[20];
  359.     int  FireSpeed;
  360.  
  361.  /*
  362.   *    PROTOTYPES
  363.   */
  364.  int PASCAL WinMain (HANDLE, HANDLE, LPSTR, int);
  365.  long FAR PASCAL _export WindowProcedure (HWND, unsigned, WORD, LONG);
  366.  BOOL FAR PASCAL AboutBox(HWND, unsigned, WORD, LONG);
  367.  BOOL FAR PASCAL ConfigBox(HWND, unsigned, WORD, LONG);
  368.  BOOL FAR PASCAL StatistikBox(HWND, unsigned, WORD, LONG);
  369.  
  370.  /* MMSYSTEM.DLL - imports MCI-functions */
  371.  DWORD FAR PASCAL MciSendString(LPSTR, LPSTR, WORD, HWND);
  372.  BOOL FAR PASCAL MciGetErrorString(DWORD, LPSTR, WORD);
  373.  DWORD FAR PASCAL MciSendCommand (WORD, WORD, DWORD, DWORD);
  374.  BOOL FAR PASCAL sndPlaySound(LPSTR lpszSoundName, WORD wFlags);
  375.  
  376.  /* Spezielle Windows 3.1 Funktionen */
  377.  BOOL FAR PASCAL RedrawWindow (HWND hwnd, const RECT FAR* lprcUpdate, HRGN hrgnUpdate, WORD flags);
  378.  
  379.  #define RDW_INVALIDATE        0x0001
  380.  #define RDW_INTERNALPAINT    0x0002
  381.  #define RDW_ERASE        0x0004
  382.  
  383.  #define RDW_VALIDATE        0x0008
  384.  #define RDW_NOINTERNALPAINT    0x0010
  385.  #define RDW_NOERASE        0x0020
  386.  
  387.  #define RDW_NOCHILDREN        0x0040
  388.  #define RDW_ALLCHILDREN     0x0080
  389.  
  390.  #define RDW_UPDATENOW        0x0100
  391.  #define RDW_ERASENOW        0x0200
  392.  
  393.  #define RDW_FRAME              0x0400
  394.  #define RDW_NOFRAME            0x0800
  395.  
  396.  
  397.  
  398.  /*
  399.   *   RETURN:
  400.   *
  401.   *   CALL AND PARAMETERS:
  402.   */
  403.  /*
  404.   *
  405.   * ------------------------------------------------------------------------ */
  406.  
  407.  /* ----- WinMain ----------------------------------------------------------
  408.   *
  409.   *    Windows Entry Function
  410.   * ---------------------------------------------------------------------- */
  411.  
  412.  int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  413.  
  414.  #pragma argsused
  415.  
  416.  HANDLE    hInstance;    /* Actual instance */
  417.  HANDLE    hPrevInstance;    /* Preious instance */
  418.  LPSTR    lpszCmdLine;    /* Command line parameter */
  419.  int    nCmdShow;    /* Window or icon? */
  420.  
  421.  {
  422.     HWND        hWindow;        /* Window handle */
  423.     HMENU        hSysMenu;        /* System menu handle */
  424.     MSG        Message;        /* Message struct */
  425.     WNDCLASS    WindowClass;        /* Window class */
  426.     TEXTMETRIC    tm;            /* Text dimensions */
  427.     HDC        hdcSystemDC;        /* Screen display context */
  428.     static char    acName[] = "hallo";    /* window class name */
  429.     int        i;            /* Counter, what else? */
  430.     char            WindowsPath[144];       /* Where is Windows? */
  431.     FILE        *wininifile;
  432.     char        winini[200];
  433.  
  434.     /* Already an application of the same type running? */
  435.     scheiss_c = hInstance;
  436.     grenade_ready = TRUE;
  437.     MCIDriverInstalled = FALSE;
  438.     soundinstalled = FALSE;
  439.     first_play_command = TRUE;
  440.     treffer_flag = 0;
  441.     if (!hPrevInstance) {
  442.         WindowClass.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  443.         WindowClass.lpfnWndProc = WindowProcedure;
  444.         WindowClass.cbClsExtra = 0;
  445.         WindowClass.cbWndExtra = 0;
  446.         WindowClass.hInstance = hInstance;
  447.         WindowClass.hIcon = LoadIcon (hInstance, (LPSTR) "MegaIcon");
  448.         WindowClass.hCursor = LoadCursor (hInstance, (LPSTR) "GAEHN");
  449.         WindowClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  450.         WindowClass.lpszMenuName = NULL;
  451.         WindowClass.lpszClassName = acName;
  452.  
  453.         /* Already existing a window of the same class? */
  454.         if (!RegisterClass (&WindowClass))
  455.             return (FALSE);
  456.  
  457.     }
  458.  
  459.     /* Get dimensions of an capital char of the actual system font */
  460.     hdcSystemDC = CreateDC("DISPLAY", NULL, NULL, NULL);
  461.     GetTextMetrics(hdcSystemDC, &tm);
  462.     cxChar = tm.tmAveCharWidth;
  463.     cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
  464.     cyCaps = tm.tmHeight + tm.tmExternalLeading;
  465.  
  466.     /* Get maximum with of one text row in pixels */
  467.     iMaxZeile = 0;
  468.     for (i = 0; i < LINENUMS; i++)
  469.         iMaxZeile = max(iMaxZeile, LOWORD(GetTextExtent(hdcSystemDC,
  470.             acText[i], strlen(acText[i]))));
  471.  
  472.     DeleteDC(hdcSystemDC);
  473.  
  474.     /* Create window */
  475.     hWindow = CreateWindow (acName,            /* Window class name */
  476.                 "Death to Mickeysoft",    /* Window title */
  477.                 WS_OVERLAPPED        /* Window style */
  478.                 |WS_CAPTION|WS_SYSMENU
  479.                 |WS_MINIMIZEBOX,
  480.                 STARTPOSX,         /* Window start */
  481.                 STARTPOSY,         /* position and */
  482.                 iMaxZeile + 10,        /* size */
  483.                 cyCaps * (LINENUMS + 2),
  484.                 NULL,
  485.                 NULL,
  486.                 hInstance,
  487.                 NULL);
  488.  
  489.     /* Append menu entry for About... function */
  490.     hSysMenu = GetSystemMenu(hWindow, FALSE);
  491.     AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
  492.     AppendMenu(hSysMenu, MF_STRING, IDM_CONFIG, "Configuration");
  493.     AppendMenu(hSysMenu, MF_STRING, IDM_STATS, "Statistics");
  494.     AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
  495.     AppendMenu(hSysMenu, MF_STRING, IDM_HELP, "HELP!");
  496.     AppendMenu(hSysMenu, MF_STRING, IDM_SYSABOUT, "About Bang...");
  497.     AppendMenu(hSysMenu, MF_STRING, IDM_ABOUTABOUT, "About About...");
  498.  
  499.     /* Show Window */
  500.     ShowWindow (hWindow, SW_SHOWMINIMIZED);
  501.     UpdateWindow (hWindow);
  502.  
  503.     /* Load Recources */
  504.     hcursor = LoadCursor(hInstance, "MegaCursor");
  505.     gaehn_cursor = LoadCursor(hInstance, "GAEHN");
  506.     hole_bitm = LoadBitmap(hInstance, "LOCH");
  507.     grenade_bitm = LoadBitmap(hInstance, "GRENADE");
  508.  
  509.     GetWindowsDirectory(WindowsPath,144);
  510.     if (WindowsPath[strlen(WindowsPath)]=='\\')
  511.      WindowsPath[strlen(WindowsPath)]='\0';
  512.     HowMuch=GetProfileString("BANG", NULL, NULL, (LPSTR)WhereBang, 51);
  513.  
  514.     if (HowMuch == 0)
  515.         {
  516.         strcpy(winini,WindowsPath);
  517.         strcat(winini,"\\win.ini");
  518.         wininifile = fopen(winini,"at");
  519.  
  520.         fprintf(wininifile,"\n[BANG]\n\n");
  521.         fprintf(wininifile, "   BBBBBB         AA       N     N     GGGGGG\n");
  522.         fprintf(wininifile, "   B      B     A    A     NN    N    G\n");
  523.         fprintf(wininifile, "   B      B    A      A    N N   N    G\n");
  524.         fprintf(wininifile, "   BBBBBB      A      A    N  N  N    G   GGG\n");
  525.         fprintf(wininifile, "   B      B    AAAAAAAA    N   N N    G      G\n");
  526.         fprintf(wininifile, "   B      B    A      A    N    NN    G      G\n");
  527.         fprintf(wininifile, "   BBBBBB      A      A    N     N     GGGGGG\n\n");
  528.         fprintf(wininifile, "Written by REMBRANDT, POWER MIKE and JOSH\n\n");
  529.         fprintf(wininifile, "Each WinDoom application is adding some rubbish to the WIN.INI\n");
  530.         fprintf(wininifile, "file. This one too !!!\n\n");
  531.         fprintf(wininifile, "Enjoy it\n\n");
  532.         strcpy(winini,"WhereBang = ");
  533.         strcat(winini,WindowsPath);
  534.         strcat(winini,"\n");
  535.         fprintf(wininifile, winini);
  536.         fprintf(wininifile, "MachineGun = BANGGUN.WAV\n");
  537.         fprintf(wininifile, "GrenadeThrower = BANGGREN.WAV\n");
  538.         fprintf(wininifile, "HastaLaVista = BANGHLVB.WAV\n");
  539.         fprintf(wininifile, "FireSpeed = 500\n");
  540.         fprintf(wininifile, "GrenadeDelay = %d\n",GRENADEDELAY);
  541.         fprintf(wininifile, "SoundMode = AUTO\n");
  542.         fclose(wininifile);
  543.         WriteProfileString("BANG","HastaLaVista","BANGHLVB.WAV");
  544.         }
  545.  
  546.     sprintf(strGrenadeDelay,"%u",GRENADEDELAY);
  547.     HowMuch=GetProfileString("BANG", "WhereBang", (LPSTR)WindowsPath, (LPSTR)WhereBang, 51);
  548.     HowMuch=GetProfileString("BANG", "MachineGun", "DING.WAV", (LPSTR)MachineGun, 13);
  549.     HowMuch=GetProfileString("BANG", "GrenadeThrower", "DING.WAV", (LPSTR)GrenadeThrower, 13);
  550.     HowMuch=GetProfileString("BANG", "HastaLaVista", "DING.WAV", (LPSTR)HastaLaVista, 13);
  551.     HowMuch=GetProfileString("BANG", "Firespeed", "100", (LPSTR)strFireSpeed, 10);
  552.     HowMuch=GetProfileString("BANG", "SoundMode", "AUTO", (LPSTR)strSoundMode, 10);
  553.     HowMuch=GetProfileString("BANG", "GrenadeDelay", strGrenadeDelay, (LPSTR)strGrenadeDelay, 10);
  554.     FireSpeed=atoi(strFireSpeed);
  555.     GrenadeDelay=atoi(strGrenadeDelay);
  556.     MCImode=AUTO;
  557.     if (strcmpi(strSoundMode,SoundModeStrings[SPEAKER]) == 0) MCImode = SPEAKER;
  558.     if (strcmpi(strSoundMode,SoundModeStrings[MCIDEVICE]) == 0) MCImode = MCIDEVICE;
  559.  
  560.     ShotsOnWinDoom=0;
  561.     ThrownGrenades=0;
  562.  
  563.     /* message loop */
  564.     while (GetMessage (&Message, NULL, 0, 0) )
  565.     {
  566.         TranslateMessage (&Message);
  567.         DispatchMessage (&Message);
  568.     }
  569.  
  570.     UnregisterClass(WindowClass.lpszClassName,WindowClass.hInstance);
  571.  
  572.     return (Message.wParam);
  573.  
  574.  }    /* this was win main ... */
  575.  
  576.  /* ---------------------------------------------------------------------- */
  577.  
  578.  
  579.  void InitSpeakerSound(void)
  580.  {
  581.     if (!soundinstalled)
  582.     {
  583.         OpenSound();
  584.         soundinstalled = TRUE;
  585.         SetSoundNoise(S_WHITE2048, 5);
  586.         SetVoiceQueueSize(1, 1000);
  587.         SetVoiceAccent(1, 200, 30, S_NORMAL, 40);
  588.     }
  589.  
  590. }
  591.  
  592.  
  593.  /* ----- OwnMciSendString -----------------------------------------------
  594.   *
  595.   *    Sends MCI Strings and handles errors
  596.   * ---------------------------------------------------------------------- */
  597.  
  598.  long PASCAL OwnMciSendString(char *SendStr, char *Information, WORD LengthInfo, WORD hCallback,
  599.                  char *Errorstr)
  600.  
  601.  {
  602.     long RetSend;
  603.     char errorstr[255], printstr[300];
  604.     int CheckError, playcommand;
  605.  
  606.     RetSend = 0;
  607.     playcommand=(SendStr[0]=='p' && SendStr[1]=='l' && SendStr[2]=='a' && SendStr[3]=='y');
  608.     CheckError = (!(strcmp(Errorstr,"dont check")==0)&&(MCImode==AUTO))
  609.             ||((MCImode==AUTO)&&playcommand&&first_play_command);
  610.     if (!WAVerror)
  611.     {
  612. //     MessageBox(NULL,SendStr,"Zu sendender String", MB_ICONSTOP | MB_TASKMODAL | MB_OK);
  613.      RetSend = MciSendString(SendStr, Information, LengthInfo, hCallback);
  614.      if ((RetSend != 0) && CheckError)
  615.      {
  616.         InitSpeakerSound();
  617.         WAVerror = TRUE;
  618.         MCIDriverInstalled = FALSE;
  619.  
  620.         MciGetErrorString(RetSend,errorstr,255);
  621.         strcpy(printstr,"Error location: ");
  622.         strcat(printstr,Errorstr);
  623.         strcat(printstr,"\n\n");
  624.         strcat(printstr,"Command: ");
  625.         strcat(printstr,SendStr);
  626.         strcat(printstr,"\n\n");
  627.         strcat(printstr,"Errormessage: ");
  628.         strcat(printstr,errorstr);
  629.         if (!(strcmp(Errorstr,"")==0)&&!(playcommand&&first_play_command))
  630.             MessageBox(NULL, printstr,"MCI-Error message",MB_TASKMODAL | MB_ICONSTOP | MB_OK);
  631.  
  632.      }
  633.     }
  634.     else if (MCImode == MCIDEVICE)
  635.         MciSendString(SendStr, Information, LengthInfo, hCallback);
  636.     if (playcommand) first_play_command = FALSE;
  637.     return(RetSend);
  638.  }
  639.  
  640.  
  641.  /* ---------------------------------------------------------------------- */
  642.  
  643.  
  644.  /* ----- BallerBumm -----------------------------------------------------
  645.   *
  646.   *    Do the great bang one time
  647.   * ---------------------------------------------------------------------- */
  648.  void    krawumm(WhatBaller)
  649.  
  650.     int WhatBaller;
  651.  
  652.  {
  653.     int     posx, posy;
  654.     int    i;
  655.     POINT     ptcursorpos;
  656.     HDC    hdcvar;            /* multi purpose handle */
  657.  
  658.     switch (WhatBaller)
  659.     {
  660.         case 1:
  661.             GetCursorPos((LPPOINT)&ptcursorpos);
  662.             posx = ptcursorpos.x - rangex / 2 - HALF_SIZE;
  663.             posy = ptcursorpos.y - rangey / 2 - HALF_SIZE;
  664.             treffer_flag = -1;
  665.  
  666.             /* Display shooting hole */
  667.  
  668.             hdcvar = CreateCompatibleDC(screen_hdc);
  669.             SelectObject(hdcvar, hole_bitm);
  670.             SetMapMode(hdcvar, GetMapMode(screen_hdc));
  671.             DPtoLP(hdcvar, &ptSize_hole, 1);
  672.             BitBlt(screen_hdc, posx+random(rangex), posy+random(rangex), ptSize_hole.x,
  673.                 ptSize_hole.y, hdcvar, ptOrg.x, ptOrg.y, SRCAND);
  674.             DeleteDC(hdcvar);
  675.  
  676.  
  677.             ShotsOnWinDoom++;
  678.  
  679.             /* Play digitized sound via prepared MCI */
  680.             OwnMciSendString("play bumm from 0",(LPSTR)NULL,0,0,"dont check");
  681.             if (soundinstalled && (!speaker_explosion))
  682.                 {
  683.                     SetVoiceSound(1, (long)(500) << 16, 1);
  684.                     StartSound();
  685.                 }
  686.             break;
  687.         case 2:
  688.             treffer_flag = -1;
  689.  
  690.             /* Display grenade hole */
  691.  
  692.             hdcvar = CreateCompatibleDC(screen_hdc);
  693.             SelectObject(hdcvar, grenade_bitm);
  694.             SetMapMode(hdcvar, GetMapMode(screen_hdc));
  695.             DPtoLP(hdcvar, &ptSize_grenade, 1);
  696.  
  697.             BitBlt(screen_hdc, grenade_x, grenade_y, ptSize_grenade.x,
  698.                 ptSize_grenade.y, hdcvar, ptOrg.x, ptOrg.y, SRCAND);
  699.  
  700.             DeleteDC(hdcvar);
  701.  
  702.             ThrownGrenades++;
  703.             break;
  704.     }
  705.  
  706.  }
  707.  /* ---------------------------------------------------------------------- */
  708.  
  709.  /* ----- InitMciDriver --------------------------------------------------
  710.   *
  711.   *    Prepares the MCI-driver
  712.   * ---------------------------------------------------------------------- */
  713.  void    InitMciDriver()
  714.  
  715.  {
  716.     char str[100];
  717.     char test[100];
  718.     char open[100];
  719.  
  720.     FILE *t;
  721.  
  722.     /* Are there any devices present which can play waves? */
  723.     DWORD Device_Count;
  724.  
  725.     MCI_SYSINFO_PARMS Info;
  726.  
  727.     if ((!MCIDriverInstalled) && (MCImode == AUTO) || (MCImode == MCIDEVICE))
  728.     {
  729.         Info.dwCallback=NULL;
  730.         Info.lpstrReturn=(LPSTR)(LPDWORD)&Device_Count;
  731.         Info.dwRetSize=sizeof(Device_Count);
  732.         Info.wDeviceType=MCI_DEVTYPE_WAVEFORM_AUDIO;
  733.         /* All wave-devices - lift your finger! */
  734.         MciSendCommand(NULL,MCI_SYSINFO,MCI_SYSINFO_QUANTITY,(DWORD)(LPMCI_SYSINFO_PARMS)&Info);
  735.                                      /* ^^^ Oh my god! I like those CASTs - really funny! */
  736.         MCIDriverInstalled=(Device_Count>0);
  737.  
  738.         /* That┤s it! */
  739.  
  740.         if (MCIDriverInstalled)
  741.         {
  742.             wsprintf((LPSTR)test,"%s\\patsch.wav",(LPSTR)WhereBang);
  743.             if ((t=fopen(test,"r"))==NULL)
  744.              sndPlaySound(NULL,SND_SYNC);
  745.             else
  746.              {
  747.               fclose(t);
  748.               sndPlaySound((LPSTR)test,SND_SYNC);
  749.              }
  750.  
  751.             WAVerror = FALSE;
  752.             wsprintf((LPSTR)open,"open %s\\", (LPSTR)WhereBang);
  753.  
  754.             strcpy(test,open);
  755.             strcat(test,MachineGun);
  756.             strcat(test," type waveaudio alias bumm");
  757.  
  758.             OwnMciSendString((LPSTR)test,(LPSTR)NULL,0,0,"");
  759.  
  760.             strcpy(test,open);
  761.             strcat(test,GrenadeThrower);
  762.             strcat(test," type waveaudio alias krawumm");
  763.  
  764.             OwnMciSendString((LPSTR)test,(LPSTR)NULL,0,0,"Error 1");
  765.  
  766.             strcpy(test,open);
  767.             strcat(test,HastaLaVista);
  768.             strcat(test," type waveaudio alias hlvb");
  769.  
  770.             OwnMciSendString((LPSTR)test,(LPSTR)NULL,0,0,"Error 2");
  771.  
  772.         }
  773.     }
  774.  }
  775.  /* ---------------------------------------------------------------------- */
  776.  
  777.  /* ----- CloseMciDriver -------------------------------------------------
  778.   *
  779.   *    Closes the MCI-driver
  780.   * ---------------------------------------------------------------------- */
  781.  void    CloseMciDriver()
  782.  {
  783.     if (MCIDriverInstalled)
  784.     {
  785.         MCIDriverInstalled = FALSE;
  786.         OwnMciSendString("close bumm",(LPSTR)NULL,0,0,"Error 3");
  787.         OwnMciSendString("close krawumm",(LPSTR)NULL,0,0,"Error 4");
  788.         OwnMciSendString("close hlvb",(LPSTR)NULL,0,0,"Error 5");
  789.     }
  790.  }
  791.  /* ----------------------------------------------------------------------
  792.     restorescreen() rebuilds the whole screen including desktop, icons,
  793.     windows and children of the windows! Don't ask, why mickeysoft has not
  794.     build in the function "RedrawWindow()" before Windows 3.1?!?!
  795.     Look out for BANG 1.0 and the solution without "RedrawWindow"-function!
  796.     It's funny!
  797.     ---------------------------------------------------------------------- */
  798.  
  799.  void    restorescreen()
  800.  {
  801.     if (treffer_flag)
  802.     {
  803.      InvalidateRgn(GetDesktopWindow(),NULL,TRUE);
  804.      RedrawWindow(NULL,NULL,NULL,RDW_UPDATENOW | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_INTERNALPAINT);
  805.      treffer_flag = 0;
  806.     }
  807.  }
  808.  
  809.  long FAR PASCAL _export WindowProcedure (hWnd, uiMessage, wParam, lParam)
  810.  
  811.  HWND        hWnd;        /* Window handle */
  812.  unsigned    uiMessage;    /* Message number */
  813.  WORD        wParam;        /* wParam and lParam contain */
  814.  LONG        lParam;        /* additional information */
  815.  
  816.  {
  817.     HDC        hDisplayContext;    /* Display context handle
  818.                            for window function */
  819.     PAINTSTRUCT    PaintStructure;        /* Info for window
  820.                            repainting */
  821.     HDC        hdcvar;            /* multi purpose handle */
  822.     int         i;
  823.     POINT         ptcursorpos;
  824.     static int    ballerbumm = 0;
  825.     static int    cxClientArea, cyClientArea;
  826.                         /* Width and height of
  827.                            client area */
  828.     static int    cyOffset;        /* Vertical offset for text
  829.                            display */
  830.     FARPROC        lpAboutProc;        /* Pointer to the About
  831.                            dialog box function */
  832.     FARPROC         lpConfigProc;           /* Pointer to the config
  833.                            box function        */
  834.     FARPROC         lpStatistikProc;    /* Pointer to the statstic
  835.                            box function        */
  836.     char        InfoStr[42];            /* additional information */
  837.     char        test[100];        /* all round - variable */
  838.  
  839.     switch (uiMessage){
  840.     case WM_CREATE :
  841.             /* Get screen dimensions */
  842.             cxSize = GetSystemMetrics(SM_CXSCREEN);
  843.             cySize = GetSystemMetrics(SM_CYSCREEN);
  844.  
  845.             /* Back to where the action is... */
  846.             return(0);
  847.     case WM_SIZE :
  848.             /* Get client area width and height for centered
  849.                text display */
  850.             cxClientArea = LOWORD(lParam);
  851.             cyClientArea = HIWORD(lParam);
  852.  
  853.             if (wParam == SIZENORMAL) {
  854.                 SetCursor(hcursor);
  855.                 SetCapture(hWnd);
  856.                 ballerbumm = 1;
  857.                 speaker_explosion = FALSE;
  858.                 grenade_ready = TRUE;
  859.                 soundinstalled = FALSE;
  860.                 if (!hdc_in_use)
  861.                 {
  862.                     screen_hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
  863.                     hdcmem = CreateCompatibleDC(screen_hdc);
  864.                     cxSize = GetSystemMetrics(SM_CXSCREEN);
  865.                     rangex = cxSize / RANGEXDIV;
  866.                     cySize = GetSystemMetrics(SM_CYSCREEN);
  867.                     rangey = cySize / RANGEYDIV;
  868.                     screen_bitm = CreateCompatibleBitmap(screen_hdc,
  869.                         cxSize, cySize);
  870.                     SelectObject(hdcmem, screen_bitm);
  871.                     ptOrg.x = 0;
  872.                     ptOrg.y = 0;
  873.                     DPtoLP (hdcmem, &ptOrg, 1);
  874.  
  875.                     hdcvar = CreateCompatibleDC(screen_hdc);
  876.                     SelectObject(hdcvar, grenade_bitm);
  877.                     SetMapMode(hdcvar, GetMapMode(screen_hdc));
  878.                     GetObject(grenade_bitm, sizeof(BITMAP), (LPSTR) &bm);
  879.                     ptSize_grenade.x = bm.bmWidth;
  880.                     ptSize_grenade.y = bm.bmHeight;
  881.                     DPtoLP(hdcvar, &ptSize_grenade, 1);
  882.                     DeleteDC(hdcvar);
  883.  
  884.                     hdcvar = CreateCompatibleDC(screen_hdc);
  885.                     SelectObject(hdcvar, hole_bitm);
  886.                     SetMapMode(hdcvar, GetMapMode(screen_hdc));
  887.                     GetObject(hole_bitm, sizeof(BITMAP), (LPSTR) &bm);
  888.                     ptSize_hole.x = bm.bmWidth;
  889.                     ptSize_hole.y = bm.bmHeight;
  890.                     DPtoLP(hdcvar, &ptSize_hole, 1);
  891.                     DeleteDC(hdcvar);
  892.                     hdc_in_use = TRUE;
  893.                 }
  894.  
  895.                 /* Prepare Multimedia-Controller */
  896.  
  897.                 WAVerror = TRUE;
  898.                 InitMciDriver();
  899.                 if (MCImode == SPEAKER) InitSpeakerSound();
  900.  
  901.             }
  902.             if (wParam == SIZEICONIC) {
  903.  
  904.                 /* And now delete the bunch of device
  905.                    contexts, because there are only 6 of
  906.                    them system wide */
  907.                 KillTimer(hWnd,HASTALAVISTA);
  908.                 if (hdc_in_use)
  909.                 {
  910.                     DeleteDC(hdcvar);
  911.                     DeleteDC(hdcmem);
  912.                     hdc_in_use = FALSE;
  913.                 }
  914.                 restorescreen();
  915.                 CloseMciDriver();
  916.             }
  917.         break;
  918.     case WM_PAINT :
  919.         hDisplayContext = BeginPaint (hWnd, &PaintStructure);
  920.  
  921.         /* Get vertical offset for text display */
  922.         cyOffset = max(0, cyClientArea - (LINENUMS * cyCaps));
  923.  
  924.         /* Display text centered in window */
  925.         for (i = 0; i < LINENUMS; i++){
  926.             SetTextAlign(hDisplayContext, TA_CENTER | TA_TOP);
  927.             TextOut (hDisplayContext, cxClientArea / 2,
  928.                 cyOffset+(i * cyCaps), acText[i],
  929.                 (int)strlen(acText[i]));
  930.             SetTextAlign(hDisplayContext, TA_LEFT | TA_TOP);
  931.         }
  932.         EndPaint(hWnd, &PaintStructure);
  933.         break;
  934.     case WM_LBUTTONUP :
  935.         if (soundinstalled)
  936.              StopSound();
  937.         KillTimer(hWnd, PENG);
  938.         return(0);
  939.     case WM_TIMER :
  940.         switch (wParam)
  941.         {
  942.         case PENG :
  943.             krawumm(1);
  944.             return(0);
  945.         case GRENADE:
  946.             KillTimer(hWnd, GRENADE);
  947.              grenade_ready = TRUE;
  948.             krawumm(2);
  949.             if (soundinstalled)
  950.                 {
  951.                 StopSound();
  952.                 SetVoiceSound(1, (long)(200) << 16, EXPLOSIONDELAY);
  953.                 StartSound();
  954.                 explosion_counter=EXPLOSIONNUMBER;
  955.                  speaker_explosion = TRUE;
  956.                  }
  957.             SetTimer(hWnd, ENDGRENADE, soundinstalled?EXPLOSIONDELAY:ENDDELAY, NULL);
  958.         case ENDGRENADE:
  959.             OwnMciSendString("status krawumm mode",(LPSTR)InfoStr,42,0,"Error 6");
  960.             if ((soundinstalled) || (strcmp(InfoStr,OldInfoStr) != 0))
  961.             {
  962.                 if (soundinstalled)
  963.                     {
  964.                     StopSound();
  965.                     if (explosion_counter--)
  966.                         {
  967.                         SetVoiceSound(1, (long)(100+random(100)) << 16, EXPLOSIONDELAY);
  968.                         StartSound();
  969.                         }
  970.                     else
  971.                         {
  972.                         speaker_explosion = FALSE;
  973.                         explosion_counter = 0;
  974.                         KillTimer(hWnd,ENDGRENADE);
  975.                         }
  976.                      }
  977.                  return(0);
  978.             }
  979.             else
  980.             {
  981.                 KillTimer(hWnd,ENDGRENADE);
  982.                 return(0);
  983.             }
  984.         case HASTALAVISTA:
  985.             OwnMciSendString("status hlvb mode",(LPSTR)InfoStr,42,0,"Error 7");
  986.             grenade_ready = TRUE;
  987.             if ((soundinstalled) || (strcmp(InfoStr,OldInfoStr) != 0))
  988.             {
  989.                 /*CloseMciDriver();*/
  990.                 KillTimer(hWnd,HASTALAVISTA);
  991.                 if (soundinstalled)
  992.                 {
  993.                     CloseSound();
  994.                     soundinstalled = FALSE;
  995.                 }
  996.                 return(0);
  997.             }
  998.             else
  999.             {
  1000.                 return(0);
  1001.             }
  1002.         }
  1003.  
  1004.     case WM_LBUTTONDOWN :
  1005.         if (ballerbumm) {
  1006.             krawumm(1);
  1007.             SetTimer(hWnd, PENG, 501-FireSpeed, NULL);
  1008.             return(0);
  1009.         }
  1010.         break;
  1011.     case WM_RBUTTONDBLCLK :
  1012.         if (ballerbumm) {
  1013.             KillTimer(hWnd, PENG);
  1014.             KillTimer(hWnd, GRENADE);
  1015.             KillTimer(hWnd, ENDGRENADE);
  1016.             ballerbumm = 0;
  1017.             OwnMciSendString("stop bumm",(LPSTR)NULL,0,0,"Error 8");
  1018.             OwnMciSendString("stop krawumm",(LPSTR)NULL,0,0,"Error 9");
  1019.             OwnMciSendString("play hlvb from 0",(LPSTR)NULL,0,0,"Error 10");
  1020.             ReleaseCapture();
  1021.             SetCursor(gaehn_cursor);
  1022.             OwnMciSendString("status hlvb mode",(LPSTR)OldInfoStr,42,0,"Error 11");
  1023.             if (!soundinstalled)
  1024.                 SetTimer(hWnd, HASTALAVISTA, ENDDELAY, NULL);
  1025.             return(0);
  1026.         }
  1027.         break;
  1028.     case WM_RBUTTONDOWN :
  1029.         if (ballerbumm && grenade_ready)
  1030.          {
  1031.             grenade_ready = FALSE;
  1032.             GetCursorPos((LPPOINT)&ptcursorpos);
  1033.             grenade_x = ptcursorpos.x - ptSize_grenade.x/2;
  1034.             grenade_y = ptcursorpos.y - ptSize_grenade.y/2;
  1035.             OwnMciSendString("stop bumm",(LPSTR)NULL,0,0,"Error 12");
  1036.             OwnMciSendString("stop krawumm",(LPSTR)NULL,0,0,"Error 13");
  1037.             OwnMciSendString("play krawumm from 0",(LPSTR)NULL,0,0,"Error 14");
  1038.             OwnMciSendString("status krawumm mode",(LPSTR)OldInfoStr,42,0,"Error 15");
  1039.             SetTimer(hWnd, GRENADE, GrenadeDelay, NULL);
  1040.          }
  1041.         return(0);
  1042.     case WM_SYSCOMMAND:
  1043.         switch (wParam)
  1044.         {
  1045.         case IDM_SYSABOUT:
  1046.               lpAboutProc = MakeProcInstance(AboutBox, scheiss_c);
  1047.               DialogBox(scheiss_c, "MEGAABOUT", hWnd,    lpAboutProc);
  1048.               FreeProcInstance(lpAboutProc);
  1049.               break;
  1050.         case IDM_ABOUTABOUT:
  1051.                lpAboutProc = MakeProcInstance(AboutBox, scheiss_c);
  1052.                DialogBox(scheiss_c, "ABOUTABOUT", hWnd,    lpAboutProc);
  1053.                FreeProcInstance(lpAboutProc);
  1054.                break;
  1055.         case IDM_CONFIG:
  1056.                lpConfigProc = MakeProcInstance(ConfigBox, scheiss_c);
  1057.                DialogBox(scheiss_c, "CONFIG", hWnd, lpConfigProc);
  1058.                FreeProcInstance(lpConfigProc);
  1059.                break;
  1060.         case IDM_STATS:
  1061.                lpStatistikProc = MakeProcInstance(StatistikBox, scheiss_c);
  1062.                DialogBox(scheiss_c, "STATISTIK", hWnd, lpStatistikProc);
  1063.                FreeProcInstance(lpStatistikProc);
  1064.                break;
  1065.         case IDM_HELP:
  1066.                strcpy(test,WhereBang);
  1067.                strcat(test,"\\BANG.HLP");
  1068.                WinHelp(hWnd,test,HELP_INDEX,NULL);
  1069.  
  1070.                break;
  1071.         }
  1072.         break;
  1073.     case WM_DESTROY :
  1074.             KillTimer(hWnd,HASTALAVISTA);
  1075.             if (hdc_in_use)
  1076.             {
  1077.                 DeleteDC(hdcvar);
  1078.                 DeleteDC(hdcmem);
  1079.                 hdc_in_use = FALSE;
  1080.             }
  1081.             CloseMciDriver();
  1082.             if (soundinstalled)
  1083.             {
  1084.                 CloseSound();
  1085.                 soundinstalled = FALSE;
  1086.             }
  1087.             restorescreen();
  1088.             PostQuitMessage (0);
  1089.  
  1090.             /* Back to where the action is... */
  1091.             return(0);
  1092.     }
  1093.     if (ballerbumm)
  1094.         return(0);
  1095.     else
  1096.         return (DefWindowProc (hWnd, uiMessage, wParam, lParam));
  1097.  
  1098.  }    /* this was the window function */
  1099.  
  1100.  /* ----- AboutBox -------------------------------------------------------
  1101.   *
  1102.   * About box function
  1103.   * ---------------------------------------------------------------------- */
  1104.  BOOL FAR PASCAL AboutBox(hDialog, uiMeldung, wParam, lParam)
  1105.  
  1106.  #pragma argsused
  1107.  
  1108.  HWND        hDialog;    /* Dialog box handle */
  1109.  unsigned       uiMeldung;    /* Dialog box message */
  1110.  WORD        wParam;        /* wParam und lParam contain */
  1111.  LONG        lParam;        /* additional informations */
  1112.  {
  1113.     switch (uiMeldung){
  1114.  
  1115.         /* Dialog box initialized: only default actions */
  1116.         case WM_INITDIALOG:
  1117.             return(TRUE);
  1118.  
  1119.         /* User likes to keep on firing */
  1120.         case WM_COMMAND:
  1121.             if (wParam == ID_OK)
  1122.              {
  1123.               EndDialog(hDialog, TRUE);
  1124.               return(TRUE);
  1125.              }
  1126.             break;
  1127.     }
  1128.     return(FALSE);
  1129.  }
  1130.  /* ----- ConfigurationBox -----------------------------------------------
  1131.   *
  1132.   * Configuration box function
  1133.   * ---------------------------------------------------------------------- */
  1134.  BOOL FAR PASCAL ConfigBox(hDialog, uiMeldung, wParam, lParam)
  1135.  
  1136.  #pragma argsused
  1137.  
  1138.  HWND        hDialog;    /* Dialog box handle */
  1139.  unsigned       uiMeldung;    /* Dialog box message */
  1140.  WORD        wParam;        /* wParam und lParam contain */
  1141.  LONG        lParam;        /* additional informations */
  1142.  {
  1143.  
  1144.  BOOL     btest;
  1145.  int    i;
  1146.  long    newdelay;
  1147.  char    Buffer[100];
  1148.  char    *detecterror;
  1149.  
  1150.     switch (uiMeldung)
  1151.     {
  1152.  
  1153.         /* Where is the Sound? */
  1154.         case WM_INITDIALOG:
  1155.             FirePlace=FireSpeed;
  1156.             oldgrenade=GrenadeDelay;
  1157.             itoa(GrenadeDelay,strGrenadeDelay,10);
  1158.             SetDlgItemText(hDialog,ID_MG,(LPSTR)MachineGun);
  1159.             SetDlgItemText(hDialog,ID_GT,(LPSTR)GrenadeThrower);
  1160.             SetDlgItemText(hDialog,ID_HLVB,(LPSTR)HastaLaVista);
  1161.             SetDlgItemText(hDialog,ID_PATHTOSOUND,(LPSTR)WhereBang);
  1162.             SetDlgItemInt(hDialog,ID_SPEED,FirePlace,FALSE);
  1163.             SetDlgItemText(hDialog,ID_GRENADEDELAY,strGrenadeDelay);
  1164.             for (i = 0; i< 3; i++)
  1165.                 SendDlgItemMessage (hDialog,ID_SOUNDMODE,CB_ADDSTRING, 0,
  1166.                     (LONG)(LPSTR)SoundModeStrings[i]);
  1167.             SendDlgItemMessage (hDialog,ID_SOUNDMODE,CB_SELECTSTRING, 0,
  1168.                 (LONG)(LPSTR)SoundModeStrings[MCImode]);
  1169.  
  1170.             hSlider=GetDlgItem(hDialog,ID_SLIDER);
  1171.             SetScrollRange(hSlider, SB_CTL, 1, 500, TRUE);
  1172.             SetScrollPos(hSlider, SB_CTL, FirePlace, TRUE);
  1173.             return(TRUE);
  1174.         /* User wants to say something */
  1175.         case WM_VSCROLL:
  1176.             switch(wParam)
  1177.              {
  1178.               case SB_BOTTOM:
  1179.                FirePlace=1; break;
  1180.               case SB_TOP:
  1181.                FirePlace=500; break;
  1182.               case SB_LINEDOWN:
  1183.                if (FirePlace<500)
  1184.                 FirePlace++;
  1185.                break;
  1186.               case SB_LINEUP:
  1187.                if (FirePlace>1)
  1188.                 FirePlace--;
  1189.                break;
  1190.               case SB_PAGEUP:
  1191.                if (FirePlace>100)
  1192.                 FirePlace-=100;
  1193.                else
  1194.                 FirePlace=1;
  1195.                 break;
  1196.               case SB_PAGEDOWN:
  1197.                if (FirePlace<401)
  1198.                 FirePlace+=100;
  1199.                else
  1200.                 FirePlace=500;
  1201.                break;
  1202.               case SB_THUMBTRACK:
  1203.                 FirePlace=LOWORD(lParam);
  1204.                break;
  1205.              }
  1206.             SetDlgItemInt(hDialog,ID_SPEED, FirePlace, FALSE);
  1207.             SetScrollPos(hSlider, SB_CTL, FirePlace, TRUE);
  1208.         case WM_COMMAND:
  1209.          switch (wParam)
  1210.           {
  1211.            case ID_FORGET:
  1212.              GrenadeDelay=oldgrenade;
  1213.              EndDialog(hDialog, FALSE);
  1214.              return(FALSE);
  1215.            case ID_SOUNDMODE:
  1216.              GetDlgItemText (hDialog,ID_SOUNDMODE,Buffer, 100);
  1217.              for (i = 0; i< 3; i++)
  1218.                 if (strcmpi(Buffer,SoundModeStrings[i])==0)
  1219.                     MCImode=i;
  1220.              return(TRUE);
  1221.            case ID_GRENADEDELAY:
  1222.              GetDlgItemText(hDialog,ID_GRENADEDELAY,(LPSTR)Buffer,100);
  1223.              newdelay=strtol(Buffer,&detecterror,10);
  1224.              for(i=strlen(Buffer);i>0 && Buffer[i-1]==' ';i--,Buffer[i]=0);
  1225.              if (*detecterror != 0 || newdelay < 0 || newdelay > 30000)
  1226.                 {
  1227.                 MessageBeep(0);
  1228.                 SetDlgItemText(hDialog,ID_GRENADEDELAY,strGrenadeDelay);
  1229.                 return(FALSE);
  1230.                 }
  1231.              else
  1232.                 {
  1233.                 GrenadeDelay = newdelay;
  1234.                 return(TRUE);
  1235.                 }
  1236.            case ID_SAVE:
  1237.              GetDlgItemText(hDialog,ID_MG,(LPSTR)MachineGun,13);
  1238.              GetDlgItemText(hDialog,ID_GT,(LPSTR)GrenadeThrower,13);
  1239.              GetDlgItemText(hDialog,ID_HLVB,(LPSTR)HastaLaVista,13);
  1240.              GetDlgItemText(hDialog,ID_PATHTOSOUND,(LPSTR)WhereBang,50);
  1241.              GetDlgItemText(hDialog,ID_GRENADEDELAY,(LPSTR)strGrenadeDelay,50);
  1242.              FireSpeed=GetDlgItemInt(hDialog,ID_SPEED,&btest,FALSE);
  1243.              WriteProfileString("BANG","MachineGun",(LPSTR)MachineGun);
  1244.              WriteProfileString("BANG","GrenadeThrower",(LPSTR)GrenadeThrower);
  1245.              WriteProfileString("BANG","HastaLaVista",(LPSTR)HastaLaVista);
  1246.              WriteProfileString("BANG","WhereBang",(LPSTR)WhereBang);
  1247.              itoa(FireSpeed,strFireSpeed,10);
  1248.              WriteProfileString("BANG","Firespeed",(LPSTR)strFireSpeed);
  1249.              itoa(GrenadeDelay,strGrenadeDelay,10);
  1250.              WriteProfileString("BANG","GrenadeDelay",(LPSTR)strGrenadeDelay);
  1251.              WriteProfileString("BANG","SoundMode",(LPSTR)SoundModeStrings[MCImode]);
  1252.              EndDialog(hDialog, TRUE);
  1253.              return(TRUE);
  1254.  
  1255.           }
  1256.           break;
  1257.         default:
  1258.              return(FALSE);
  1259.     }
  1260.     return(FALSE);
  1261.  }
  1262.  /* ----- StatistikBox ---------------------------------------------------
  1263.   *
  1264.   * statistic box function
  1265.   * ---------------------------------------------------------------------- */
  1266.  BOOL FAR PASCAL StatistikBox(hDialog, uiMeldung, wParam, lParam)
  1267.  
  1268.  #pragma argsused
  1269.  
  1270.  HWND        hDialog;    /* Dialog box handle */
  1271.  unsigned       uiMeldung;    /* Dialog box message */
  1272.  WORD        wParam;        /* wParam und lParam contain */
  1273.  LONG        lParam;        /* additional informations */
  1274.  {
  1275.  
  1276.  BOOL btest;
  1277.  
  1278.     switch (uiMeldung)
  1279.     {
  1280.  
  1281.         /* Where is the Sound? */
  1282.         case WM_INITDIALOG:
  1283.             SetDlgItemInt(hDialog,ID_SHOTS,ShotsOnWinDoom, FALSE);
  1284.             SetDlgItemInt(hDialog,ID_GRENADES,ThrownGrenades, FALSE);
  1285.             return(TRUE);
  1286.         case WM_COMMAND:
  1287.          switch (wParam)
  1288.           {
  1289.            case ID_OK:
  1290.              EndDialog(hDialog, TRUE);
  1291.              return(TRUE);
  1292.            case ID_RESET:
  1293.              ShotsOnWinDoom=0;
  1294.              ThrownGrenades=0;
  1295.              SetDlgItemInt(hDialog,ID_SHOTS,ShotsOnWinDoom,FALSE);
  1296.              SetDlgItemInt(hDialog,ID_GRENADES,ThrownGrenades,FALSE);
  1297.              break;
  1298.           }
  1299.           break;
  1300.         default:
  1301.              return(FALSE);
  1302.     }
  1303.     return(FALSE);
  1304.  }
  1305.